package com.spzx.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spzx.user.domain.Region;
import com.spzx.user.domain.UserAddress;
import com.spzx.user.mapper.UserAddressMapper;
import com.spzx.user.service.IRegionService;
import com.spzx.user.service.IUserAddressService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserAddressServiceImpl extends ServiceImpl<UserAddressMapper, UserAddress> implements IUserAddressService{
    @Resource
    private UserAddressMapper userAddressMapper;
    @Resource
    private IRegionService regionService;

    @Override
    public List<UserAddress> selectUserAddressList(UserAddress userAddress){
        List<UserAddress> userAddresses = userAddressMapper.selectUserAddressList(userAddress);
        userAddresses.forEach(item -> {
            item.setProvinceName(regionService.getOne(new LambdaQueryWrapper<Region>().eq(Region::getCode, item.getProvinceCode())).getName());
            item.setCityName(regionService.getOne(new LambdaQueryWrapper<Region>().eq(Region::getCode, item.getCityCode())).getName());
            item.setDistrictName(regionService.getOne(new LambdaQueryWrapper<Region>().eq(Region::getCode, item.getDistrictCode())).getName());
        });
        return userAddresses;
    }

}
